]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensions-tool: Prepare for alternative templates
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 6 Nov 2019 09:06:11 +0000 (10:06 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Tue, 7 Apr 2020 20:27:00 +0000 (20:27 +0000)
The template used when creating a new extension is intentionally
minimal, as the sample code in the old extensions-tool proved to
be annoying more often than not.

However as we support per-command options, we don't have to limit
ourselves to a single template, and can offer alternatives for
common use cases.

To prepare for that, namespace the existing template by moving it
into a subfolder.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/812

subprojects/extensions-tool/src/command-create.c
subprojects/extensions-tool/src/gnome-extensions-tool.gresource.xml
subprojects/extensions-tool/src/template/extension.js [deleted file]
subprojects/extensions-tool/src/template/stylesheet.css [deleted file]
subprojects/extensions-tool/src/templates/plain/extension.js [new file with mode: 0644]
subprojects/extensions-tool/src/templates/plain/stylesheet.css [new file with mode: 0644]

index 25fcc5ba0fc6b68f4e995d13ebde7b5ac9546d1c..000cf94d25f710558bc20207a866d012c217aa2b 100644 (file)
@@ -26,6 +26,8 @@
 #include "common.h"
 #include "config.h"
 
+#define TEMPLATES_PATH "/org/gnome/extensions-tool/templates"
+
 static char *
 get_shell_version (GError **error)
 {
@@ -85,21 +87,30 @@ create_metadata (GFile       *target_dir,
 }
 
 
-#define TEMPLATE_PATH "/org/gnome/extensions-tool/template"
 static gboolean
-copy_extension_template (GFile *target_dir, GError **error)
+copy_extension_template (const char *template, GFile *target_dir, GError **error)
 {
   g_auto (GStrv) templates = NULL;
+  g_autofree char *path = NULL;
   char **s;
 
-  templates = g_resources_enumerate_children (TEMPLATE_PATH, 0, NULL);
+  path = g_strdup_printf (TEMPLATES_PATH "/%s", template);
+  templates = g_resources_enumerate_children (path, 0, NULL);
+
+  if (templates == NULL)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+                   "No template %s", template);
+      return FALSE;
+    }
+
   for (s = templates; *s; s++)
     {
       g_autoptr (GFile) target = NULL;
       g_autoptr (GFile) source = NULL;
       g_autofree char *uri = NULL;
 
-      uri = g_strdup_printf ("resource://%s/%s", TEMPLATE_PATH, *s);
+      uri = g_strdup_printf ("resource://%s/%s", path, *s);
       source = g_file_new_for_uri (uri);
       target = g_file_get_child (target_dir, *s);
 
@@ -157,7 +168,7 @@ create_extension (const char *uuid, const char *name, const char *description)
       return FALSE;
     }
 
-  if (!copy_extension_template (dir, &error))
+  if (!copy_extension_template ("plain", dir, &error))
     {
       g_printerr ("%s\n", error->message);
       return FALSE;
index 2aad7b1ce4e99232a74a28769b541ea2a6668c60..dce8d5c666088072176616528b646441b0de58ee 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/extensions-tool">
-    <file>template/extension.js</file>
-    <file>template/stylesheet.css</file>
+    <file>templates/plain/extension.js</file>
+    <file>templates/plain/stylesheet.css</file>
   </gresource>
 </gresources>
diff --git a/subprojects/extensions-tool/src/template/extension.js b/subprojects/extensions-tool/src/template/extension.js
deleted file mode 100644 (file)
index 64857af..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/* extension.js
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
- */
-
-/* exported init */
-
-class Extension {
-    constructor() {
-    }
-
-    enable() {
-    }
-
-    disable() {
-    }
-}
-
-function init() {
-    return new Extension();
-}
diff --git a/subprojects/extensions-tool/src/template/stylesheet.css b/subprojects/extensions-tool/src/template/stylesheet.css
deleted file mode 100644 (file)
index 37b93f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/* Add your custom extension styling here */
diff --git a/subprojects/extensions-tool/src/templates/plain/extension.js b/subprojects/extensions-tool/src/templates/plain/extension.js
new file mode 100644 (file)
index 0000000..64857af
--- /dev/null
@@ -0,0 +1,34 @@
+/* extension.js
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+/* exported init */
+
+class Extension {
+    constructor() {
+    }
+
+    enable() {
+    }
+
+    disable() {
+    }
+}
+
+function init() {
+    return new Extension();
+}
diff --git a/subprojects/extensions-tool/src/templates/plain/stylesheet.css b/subprojects/extensions-tool/src/templates/plain/stylesheet.css
new file mode 100644 (file)
index 0000000..37b93f2
--- /dev/null
@@ -0,0 +1 @@
+/* Add your custom extension styling here */